package cn.wtg.kotlindemo.testRxjava3

import androidx.databinding.ObservableField
import cn.wtg.kotlinlib.baseUi.BaseActivity
import cn.wtg.kotlinlib.baseViewModel.BaseActivityLifecycleVM
import com.scwang.smart.refresh.layout.listener.OnRefreshListener

/**
 * author: wtg
 * time: 2022/12/17
 * desc:
 */
class TestRxjavaVM(mActivity: BaseActivity) : BaseActivityLifecycleVM(mActivity) {
    var textContent = ObservableField("测试")

    var smartRefreshStyle: SmartRefreshStyle? = null
    var onRefreshListener : OnRefreshListener? = null //下拉刷新的监听

    override fun initView() {
        super.initView()
        smartRefreshStyle = SmartRefreshStyle()
        smartRefreshStyle!!.autoRefresh.set(true)
        onRefreshListener = OnRefreshListener { getData() }
    }

    fun getData() {
        smartRefreshStyle?.finishRefresh?.set(false)
        TestRxjavaModel.singleton.getWeatherData(object : BaseObserver<List<BrandBannerBean>>() {
            override fun onSuccess(data: HttpResult<List<BrandBannerBean>>?) {
                textContent.set(data.toString())
            }

            override fun onFinish() {
                super.onFinish()
                smartRefreshStyle?.finishRefresh?.set(true)
            }
        })
    }

}